/* GUI CONVERTED from socrrp.p (converter v1.76) Wed Jan 23 23:00:17 2002 */
/* socrrp.p  SALES ORDER CREDIT REPORT                                       */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.14.1.9 $                                                              */
/*V8:ConvertMode=Report                                                      */
/* REVISION: 5.0      LAST MODIFIED: 03/09/90   BY: ftb   *B619*             */
/* REVISION: 6.0      LAST MODIFIED: 10/17/90   BY: pml   *D106*             */
/* REVISION: 6.0      LAST MODIFIED: 04/05/91   BY: bjb   *D507*             */
/* REVISION: 6.0      LAST MODIFIED: 08/21/91   BY: bjb   *D811*             */
/* REVISION: 6.0      LAST MODIFIED: 11/15/91   BY: afs   *D933*             */
/* REVISION: 7.0      LAST MODIFIED: 03/26/92   BY: dld   *F322*             */
/* REVISION: 7.3      LAST MODIFIED: 01/26/93   BY: tjs   *G599*             */
/* REVISION: 7.3      LAST MODIFIED: 02/11/93   BY: tjs   *G672*             */
/* REVISION: 7.3      LAST MODIFIED: 10/25/93   BY: tjs   *GG58*             */
/* REVISION: 7.4      LAST MODIFIED: 02/02/94   BY: dpm   *FL59*             */
/* REVISION: 7.4      LAST MODIFIED: 02/21/94   BY: tjs   *H188*             */
/* REVISION: 7.4      LAST MODIFIED: 01/16/95   BY: jpm   *G0CF*             */
/* REVISION: 8.5      LAST MODIFIED: 07/21/95   BY: tjs   *J04F*             */
/*                                   08/08/95   BY: srk   *J06N*             */
/* REVISION: 7.4      LAST MODIFIED: 07/27/95   BY: bcm   *G0SP*             */
/* REVISION: 7.4      LAST MODIFIED: 10/02/95   BY: jym   *G0XY*             */
/* REVISION: 8.5      LAST MODIFIED: 07/27/95   BY: taf   *J053*             */
/* REVISION: 8.5      LAST MODIFIED: 07/19/96   BY: taf *J0ZZ*               */
/* REVISION: 8.5      LAST MODIFIED: 04/23/97   BY: *J1LV* Aruna Patil       */
/* REVISION: 8.5      LAST MODIFIED: 08/14/97   BY: *J1Z0* Ajit Deodhar      */
/* REVISION: 8.5      LAST MODIFIED: 02/11/98   BY: *J2F1* Mandar K.         */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 04/23/98   BY: *L00L* EvdGevel          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* REVISION: 8.6E     LAST MODIFIED: 07/15/98   BY: *L024* Steve Goeke       */
/* REVISION: 8.6E     LAST MODIFIED: 04/12/99   BY: *K20F* Ranjit Jain       */
/* REVISION: 8.6E     LAST MODIFIED: 09/28/99   BY: *L0J4* Satish Chavan     */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* myb               */
/* REVISION: 9.1      LAST MODIFIED: 10/27/00   BY: *N0TF* Katie Hilbert     */
/* Revision: 1.14.1.7     BY: Katie Hilbert  DATE: 04/01/01 ECO: *P002* */
/* Revision: 1.14.1.8     BY: Ellen Borden   DATE: 07/06/01 ECO: *P007* */
/* $Revision: 1.14.1.9 $           BY: Ashwini G.     DATE: 01/10/02 ECO: *L194* */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE socrrp_p_1 "Include Unconfirmed"
/* MaxLen: Comment: */

&SCOPED-DEFINE socrrp_p_2 "Open Amount"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define new shared variable convertmode as character no-undo
   initial "report".
define new shared variable rndmthd like rnd_rnd_mthd.
define new shared variable so_recno as recid.
define new shared variable new_order      like mfc_logical initial no.
define new shared variable due_date_range like mfc_logical initial yes.
define new shared variable date_range     like sod_due_date.
define new shared variable date_range1    like sod_due_date.
define new shared variable display_trail  like mfc_logical initial no.
define new shared variable undo_trl2 like mfc_logical.

define variable oldcurr like so_curr no-undo.
define variable nbr like so_nbr no-undo.
define variable nbr1 like so_nbr no-undo.
define variable cust like so_bill no-undo.
define variable cust1 like so_bill no-undo.
define variable last_so_bill like so_bill no-undo.
define variable cust_name like ad_name no-undo.
define variable ord_date like so_ord_date no-undo.
define variable ord_date1 like so_ord_date no-undo.
define variable due_date like so_due_date no-undo.
define variable due_date1 like so_due_date no-undo.
define variable act_stat like so_stat no-undo.
define variable act_stat1 like so_stat no-undo.
define variable open_amt like ar_amt label {&socrrp_p_2}
   format "->>,>>>,>>>,>>9.99" no-undo.
define variable line_amt like ar_amt no-undo.
define variable l_new_so like mfc_logical initial no no-undo.
define variable l_disp   like mfc_logical initial no no-undo.
define variable include_unconf like mfc_logical initial no
   label {&socrrp_p_1}.

define new shared frame sotot.
{mfsotrla.i "NEW"}

{etdcrvar.i new}
{etvar.i &new = new}
{etrpvar.i &new = new}

/* ASSIGN ORIGINAL FORMAT TO _OLD VARIABLES */
assign
   nontax_old = nontaxable_amt:format
   taxable_old = taxable_amt:format
   line_tot_old = line_total:format
   disc_old     = disc_amt:format
   trl_amt_old = so_trl1_amt:format
   tax_amt_old = tax_amt:format
   ord_amt_old = ord_amt:format
   container_old = container_charge_total:format
   line_charge_old = line_charge_total:format.

oldcurr = "".


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
nbr            colon 20
   nbr1           label {t001.i} colon 54 skip
   cust           colon 20
   cust1          label {t001.i} colon 54 skip
   ord_date       colon 20
   ord_date1      label {t001.i} colon 54 skip
   due_date       colon 20
   due_date1      label {t001.i} colon 54 skip
   act_stat       colon 20
   act_stat1      label {t001.i} colon 54 skip(1)
   include_unconf colon 25
with frame a side-labels attr-space width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

repeat:

   if nbr1  = hi_char then nbr1 = "".
   if cust1 = hi_char then cust1 = "".
   if ord_date  = low_date then ord_date = ?.
   if ord_date1 = hi_date or ord_date1 = low_date then ord_date1 = ?.
   if due_date  = low_date then due_date = ?.
   if due_date1 = hi_date or due_date1 = low_date then due_date1 = ?.
   if act_stat1 = hi_char then act_stat1 = "".

   view frame a.

   update
      nbr
      nbr1
      cust
      cust1
      ord_date
      ord_date1
      due_date
      due_date1
      act_stat
      act_stat1
      include_unconf
   with frame a side-labels attr-space width 80.

   bcdparm = "".
   {mfquoter.i nbr       }
   {mfquoter.i nbr1      }
   {mfquoter.i cust      }
   {mfquoter.i cust1     }
   {mfquoter.i ord_date  }
   {mfquoter.i ord_date1 }
   {mfquoter.i due_date  }
   {mfquoter.i due_date1 }
   {mfquoter.i act_stat  }
   {mfquoter.i act_stat1 }
   {mfquoter.i include_unconf}

   if nbr1 = "" then nbr1 = hi_char.
   if cust1 = "" then cust1 = hi_char.
   if ord_date = ? then ord_date = low_date.
   if ord_date1 = ? then ord_date1 = hi_date.
   if due_date = ? then due_date = low_date.
   if due_date1 = ? then due_date1 = hi_date.
   if act_stat1 = "" then act_stat1 = hi_char.

   if include_unconf then due_date_range = no.
   else due_date_range = yes.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer" &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   {mfphead.i}
   last_so_bill = "".

   {hksimsg.i """" """"}
   for each so_mstr use-index so_bill no-lock where
         so_bill     >= cust     and so_bill     <= cust1 and
         so_nbr      >= nbr      and so_nbr      <= nbr1  and
         so_ord_date >= ord_date and so_ord_date <= ord_date1
         AND LOOKUP(so_site,global_user_site) > 0       /*fdn*/

      with frame b width 132 down
         break by so_bill by so_ord_date:

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame b:handle).

      /* CHECK IF ANY SALES ORDER IS BEING CREATED */
      l_new_so = no.
      {gprun.i ""sonewso.p"" "(input recid(so_mstr),
                               output l_new_so)"}
      if not l_new_so then do:

         if (oldcurr <> so_curr) or (oldcurr = "") then do:

            {gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
               "(input  so_curr,
                 output rndmthd,
                output mc-error-number)" }
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
            end.

            oldcurr = so_curr.
            {socurfmt.i}  /* SET CURRENCY FORMATS */
         end. /* IF (OLDCURR <> SO_CURR ... */

         if ((so_due_date >= due_date and so_due_date <= due_date1) or
            (due_date1 = hi_date and so_due_date = ?)) and
            so_stat >= act_stat and so_stat <= act_stat1
         then do:

            find cm_mstr where cm_addr = so_bill no-lock no-error.
            find ad_mstr where ad_addr = so_bill no-lock no-error.
            assign
               cust_name = ad_name
               line_amt = 0
               maint = no
               date_range = low_date
               date_range1 = hi_date
               so_recno = recid(so_mstr).

            /* DETERMINE ord_amt */
            {gprun.i ""sosotrl2.p""}

            /* ORD_AMT IS IN DOCUMENT CURRENCY AND IS ROUNDED PER THAT CURR */
            /* IF DOC CURR AND BASE CURR ARE NOT THE SAME THEN CALCULATE ORD*/
            /* AMOUNT USING THE BASE EXCHANGE RATE AND ROUND PER BASE CURR  */
            if so_curr = base_curr then
               open_amt = ord_amt.
            else do:

               {gprunp.i "mcpl" "p" "mc-curr-conv"
                  "(input  so_curr,
                    input  base_curr,
                    input  so_ex_rate,
                    input  so_ex_rate2,
                    input  ord_amt,
                    input  true,  /* ROUND */
                    output open_amt,
                    output mc-error-number)" }
               if mc-error-number <> 0 then do:
                  {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
               end.

            end.

            accumulate open_amt (total by so_bill).

            if last_so_bill <> so_bill then do with frame c:
               /* SET EXTERNAL LABELS */
               setFrameLabels(frame c:handle).
               display
                  cm_addr
                  cust_name
                  cm_cr_terms
                  cm_balance
                  cm_cr_limit
                  cm_cr_rating
                  cm_high_cr
                  cm_high_date
                  cm_cr_hold
               with frame c width 132 STREAM-IO /*GUI*/ .
               last_so_bill = so_bill.
            end. /* IF LAST_SO_BILL <> SO_BILL */

            display
               so_nbr
               so_ord_date
               so_conf_date
               so_due_date
               so_po
               so_cust
               so_ship
               so_cr_terms
               so_slspsn[1]
               so_slspsn[2]
               open_amt
               so_stat WITH STREAM-IO /*GUI*/ .
            l_disp = yes.
            if so_slspsn[3] <> "" or so_slspsn[4] <> "" then do:
               down 1.
               display so_slspsn[3] @ so_slspsn[1] so_slspsn[4] @ so_slspsn[2] WITH STREAM-IO /*GUI*/ .
            end.

            
/*GUI*/ {mfguirex.i  "false"} /*Replace mfrpexit*/

         end. /* IF ((SO_DUE_DATE ...*/

         if last-of(so_bill) and l_disp then do:
            underline  open_amt.
            display getTermLabel("CUSTOMER_TOTAL",19) + ":" @ so_po
               (accum total by so_bill open_amt) @ open_amt WITH STREAM-IO /*GUI*/ .
            l_disp = no.
         end. /* IF LAST-OF(SO_BILL) */

      end. /* IF NOT L_NEW_SO */
   end. /* for so_mstr */

   {mfrtrail.i}
end. /* repeat */
